﻿using System;
using System.Linq.Expressions;

namespace BestEasyCMS.Framework.Querying
{
    /// <summary>
    /// 排序
    /// </summary>
    public class OrderByClause
    {

        public OrderByClause(string propertyName, bool desc)
        {
            PropertyName = propertyName;
            Desc = desc;
        }

        /// <summary>
        /// 属性名
        /// </summary>
        public string PropertyName { get; set; }
        /// <summary>
        /// 是否为降序
        /// </summary>
        public bool Desc { get; set; }

        public static OrderByClause Create<T>(Expression<Func<T, object>> expression, bool desc)
        {
            var propertyName = PropertyNameHelper.ResolvePropertyName<T>(expression);
            var obc = new OrderByClause(propertyName, desc);
            return obc;
        }
    }
}
